﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Project.IDAL;
using Project.Models;
using SqlSugar;

namespace Project.DAL
{
    public class BaseServices<T> : SimpleClient<T>, IBaseServices<T> where T : BaseEntity, new()
    {
        private static string ConnectionString => "server=.;database=GraduationProject;uid=sa;pwd=sa";
        public BaseServices(ISqlSugarClient context = null) : base(context)
        {
            if (context == null)
            {
                base.Context = new SqlSugarClient(new ConnectionConfig()
                {
                    DbType = DbType.Sqlite,
                    InitKeyType = InitKeyType.Attribute,
                    IsAutoCloseConnection = true,
                    ConnectionString = ConnectionString
                });
                base.Context.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(T)); // 更新数据库
                base.Context.Aop.OnLogExecuting = (s, p) =>
                {
                    Console.WriteLine(s);
                };
            }
        }
    }
}
